﻿using SdmxMl.Structure;
using System.Collections.Generic;

namespace SdmxMl.Data
{
    /// <summary>
    /// Helper class to hold meta information attached to a CSV column
    /// </summary>
    public class CsvMetaHeaderCol
    {
        public BaseDimensionType BaseVar { get; set; }
        public ConceptSchemeType ConceptScheme { get; set; }
        public ConceptType Concept { get; set; }
        public CodeListType Codelist { get; set; }
        public CodeListType CodeQuality { get; set; }
        public List<string> QualitySubset { get; set; }
        public TextFormatType TextFormat { get; set; }

        public CsvMetaHeaderCol(BaseDimensionType bdt, RefVarHelper refVarHelper)
        {
            BaseVar = bdt;
            Codelist = refVarHelper.GetCodelistOfBaseDim(bdt);
            ConceptScheme = refVarHelper.GetConceptScheme(bdt.ConceptSchemeInfo);
            Concept = refVarHelper.GetConcept(bdt.ConceptInfo.Id, bdt.ConceptSchemeInfo);

            // format infos
            TextFormat = refVarHelper.GetTextFormatTypeOfBaseDim(bdt);
        }

        public void UpdateQuality(BaseDimensionType bdt, RefVarHelper refVarHelper)
        {
            CodeListType clt = refVarHelper.GetCodelistOfBaseDim(bdt);
            if (clt != null)
            {
                CodeQuality = clt;
                // Subset in quality codes
                QualitySubset = refVarHelper.GetQualityCodelistSubset(bdt);
            }
        }
    }
}
